package com.xcl.service.impl;

import com.xcl.mapper.FinancingMapper;
import com.xcl.pojo.Information;
import com.xcl.service.FinancingServiceInter;
import com.zzg.entity.Costbreakdown;
import com.zzg.entity.Finance;
import com.zzg.entity.Financing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName FinancingServiceImpl
 * @Description 到付核销的访问层实现类
 * @Author: xiaochaolei
 * @date 2021/7/22 15:33
 * @Version 1. 0
 */
@Service
public class FinancingServiceImpl implements FinancingServiceInter {
    @Autowired
    FinancingMapper financingMapper;

    @Override
    public List<Financing> getAllFinancing() {
        return financingMapper.getAllFinancing();
    }

    @Override
    public List<Financing> getAllFinancingByLimit(int page, int limit,String waybill_id,String city,String sub_id,String arrivalCity
            ,String  eeforwardingUnit,String forwardingUnit,String date,String paymentMethod,String state,String verification) {
        return financingMapper.getAllFinancingByLimit((page-1)*limit,limit,waybill_id,city,sub_id,arrivalCity
                ,eeforwardingUnit,forwardingUnit,date,paymentMethod,state,verification);
    }

    @Override
    public int updateVerification(String waybill_id ,Costbreakdown costbreakdown) {
        //根据运输单号查询到财务信息
        Finance costbreakdownById = financingMapper.getCostbreakdownById(waybill_id);
        //将查询到的财务详细id设置到财务详细当中
        costbreakdown.setCostbreakdownId(costbreakdownById.getCostbreakdownId());
        //修改财务详细信息
        financingMapper.updateCostBreakdown(costbreakdown);
        //判断状态
        if (Double.doubleToLongBits(costbreakdown.getReceivables())==Double.doubleToLongBits(costbreakdown.getRealizefee())){
            //运单状态为已结清
            costbreakdownById.setOrderstatus("已结清");
        }else if (Double.doubleToLongBits(costbreakdown.getReceivables())>Double.doubleToLongBits(costbreakdown.getRealizefee())){
            //运单状态为未结清
            costbreakdownById.setOrderstatus("未结清");
        }else{
            //运单状态为未付款
            costbreakdownById.setOrderstatus("未付款");
        }
        //修改财务信息
        financingMapper.updateFinancing(costbreakdownById);
        //修改财务状态
        return financingMapper.updateVerification(waybill_id);
    }

    @Override
    public Information getFreightinformationTableByWaybill_id(String waybill_id) {
        return financingMapper.getFreightinformationTableByWaybill_id(waybill_id);
    }
}
